'''
Author: your name
Date: 2021-04-20 10:26:47
LastEditTime: 2021-05-13 16:49:43
LastEditors: your name
Description: In User Settings Edit
FilePath: /tinyms/tinyms-api/apps/auth/notice/service.py
'''
import json
from app import db
from .model import Notice

class NoticeService():
    def save(notice):
        db.session.add(notice)
        db.session.commit()
    
    def update(notice):
        tmp_notice = Notice.query.get(notice.notice_pk)
        tmp_notice.notice_title = notice.notice_title
        tmp_notice.notice_content = notice.notice_content
        tmp_notice.notice_time = notice.notice_time
        db.session.commit()

    def list():
        notices = Notice.query.all()
        return notices

    '''
    查询通知分页列表
    '''
    def pages(page):
        pages = Notice.query.paginate(int(page),30,False) #flask_sqlalchemy提供分页方法.paginate
        return pages